<template>
	<view>
		<u-toast ref="uToast" />
		<u-modal v-model="showModel" :content="modelContent" show-cancel-button @confirm="delScreenshotControl" z-index="9999"></u-modal>
		<view class="screenText">
			<text>截屏日期: {{screenTime}}</text>
			<text style="color: #2C72F6;" @click="showModel=true">清除所有截屏</text>
		</view>
		<view>
			<u-swiper :list="list" :autoplay="false" name="img" img-mode="aspectFit" @change="changeScreen" @click="previewImg"></u-swiper>
		</view>
		<view class="screenButton">
			<u-button  type="primary" class="button" @click="launchScreenshotControl">截屏</u-button>
			<u-button type="primary" plain class="button" @click="getScreenshotControl">刷新</u-button>
		</view>
			
	</view>
</template>

<script>
import { delScreenshot, launchScreenshot } from '../../api/systemControl'
import { querySnIdScreenshot } from '../../api/userHome'
	export default {
		data() {
			return {
				screenTime: '',
				list: [],
				showModel: false,
				modelContent: '清除后将不可恢复,确认清除所有截屏?'
			}
		},
		onLoad() {
			this.getScreenshotControl()
		},
		methods: {
			getScreenshotControl() {
				querySnIdScreenshot({
					id: uni.getStorageSync('snId')
				}).then(res => {
					let data = res.data
					this.list = data.screenshot
				}).catch(err => {
					this.list = []
				})
			},
			changeScreen(e) {
				this.screenTime = this.list[e].create_time
				uni.previewImage({
					urls: this.list
				})
			},
			launchScreenshotControl() {
				launchScreenshot({
					id: uni.getStorageSync('snId'),
				}).then(res => {
					this.$refs.uToast.show({
						title: res.msg,
						icon: false,
						type: 'success'
					})
				}).catch(err => {
					this.$refs.uToast.show({
						title: err.msg,
						icon: false,
						type: 'error'
					})
				})
			},
			delScreenshotControl() {
				delScreenshot({
					id: uni.getStorageSync('snId')
				}).then(res => {
					this.getScreenshotControl()
					this.$refs.uToast.show({
						title: res.msg,
						icon: false,
						type: 'success'
					})
				}).catch(err => {
					this.$refs.uToast.show({
						title: err.msg,
						icon: false,
						type: 'error'
					})
				})
			},
			previewImg(e) {
				uni.previewImage({
					urls: [this.list[e].img]
				})
			}
			
		}
	}
</script>

<style lang="less" scoped>
	.screenText {
		display: flex;
		justify-content: space-between;
		margin: 20rpx;
		padding-top: 30rpx;
	}
	.screenButton {
		display: flex;
		margin-top: 120rpx;
		justify-content: space-between;
		.button {
			width: 300rpx;
			padding-right: 30rpx; 
			padding-left: 30rpx;
		}
	}

</style>
